#ifndef NIXONBOT_CORE_BNCS_PROTOCOL_JOINCHANNEL_H_
#define NIXONBOT_CORE_BNCS_PROTOCOL_JOINCHANNEL_H_

#include <nixonbot/core/bncs/protocol/Message.h>
#include <nixonbot/core/bncs/protocol/MessageFactory.h>

namespace nixonbot {
namespace core {
namespace bncs {
namespace protocol {

struct JoinChannelData : public QSharedData
{
  quint32 flags;
  QByteArray name;
};

class JoinChannel : public Message
{
public:
	static const int id = 0x0c;
	BNCS_MESSAGE_CLIENT_REGISTER(JoinChannel, id);

public:
	QSharedDataPointer<JoinChannelData> d;

public:
	JoinChannel()
	{
		d = new JoinChannelData();
	}
	
	virtual JoinChannel* create()
	{
		return new JoinChannel();
	}
	
	virtual quint32 id()
	{
		return id;
	}

	virtual int size()
	{
	  return sizeof(d->flags) + (d->name.size() + 1);
	}

protected:
	virtual void readFrom(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);
		
		ds >> flags;
		name = readStringFrom(ds);
		
		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}

	virtual void writeTo(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds << flags;
		writeStringTo(ds, name);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}
};

}
}
}
}

#endif
